#ifndef CONTROLLER_H_
#define CONTROLLER_H_

#include "DSP2833x_Device.h"

class Controller
{
public:
	// offline, all off/failed
	// online, ready for operation, but inactive
	enum EStates { OFFLINE = 0x0000, ONLINE = 0x0001, SELFTEST = 0x0002, FAIL = 0x0003, CRITICALFAIL = 0x0005, CHARGING = 0x0010, BALANCING = 0x0020, ERASINGFLASH = 0x0030, DATATRANSFER = 0x0040, GOOFFLINE = 0x100, GOONLINE = 0x101, MANUAL = 0x1000 };
	enum EFailStates { FS_OVERTEMP = 0x0000, FS_OVERVOLTAGE, FS_BATTOVERVOLTAGE, FS_BATTUNDERVOLTAGE, FS_BATTCONNECTIONERROR, FS_OVERCURRENT, FS_HWERROR, FS_BATTLOWTEMPERATURE, FS_BATTHIGHTEMPERATURE, FS_LOWTEMP, FS_OVERPRESSURE, FS_DISBALANCED, FS_LAST };

private:
 	int m_StateTimerTick;

public:
	void Init();
	void Update();
	void SetState(EStates state);
	EStates GetState();
	unsigned int GetFailStateWord();

private:
	void ResetErrors();

private:
	EStates	m_OPState;
	Uint32 m_CurrentReadWritePage;

	// error states
	bool m_FailStates[FS_LAST];
};

#endif /*CONTROLLER_H_*/
